home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / PASCAL / FPKPAS65.ZIP / SRCCOMP.ZIP / SOURCE / COMPILER / ASMBL.PAS next >
Encoding:
Pascal/Delphi Source File  |  1996-07-23  |  5.1 KB  |  130 lines

  1. {****************************************************************************
  2.  
  3.                    Copyright (c) 1993,96 by Florian Klämpfl
  4.  
  5.  ****************************************************************************}
  6.  
  7. unit asmbl;
  8.  
  9.   interface
  10.  
  11.   uses
  12.      globals,scanner,asmgen,hcodegen,symtable,tree
  13. {$ifdef i386}
  14.        ,i386
  15. {$else}
  16. {$endif}
  17.        ;
  18.  
  19.  
  20.      function assemble : ptree;
  21.  
  22.  
  23.   implementation
  24.  
  25.  
  26.     function assemble : ptree;
  27.  
  28.       var
  29.          s,hs : string;
  30.          c : char;
  31.          ende : boolean;
  32.          sym : psym;
  33.          code : pasmlist;
  34.          l : longint;
  35.  
  36.       begin
  37.          ende:=false;
  38.          s:='';
  39.          c:=asmgetchar;
  40.          code:=new(pasmlist,init);
  41.          while not(ende) do
  42.            begin
  43.               case c of
  44.                  'A'..'Z','a'..'z','_' : begin
  45.                       hs:='';
  46.                       while ((ord(c)>=ord('A')) and (ord(c)<=ord('Z')))
  47.                          or ((ord(c)>=ord('a')) and (ord(c)<=ord('z')))
  48.                          or ((ord(c)>=ord('0')) and (ord(c)<=ord('9')))
  49.                          or (c='_') do
  50.                         begin
  51.                            inc(byte(hs[0]));
  52.                            hs[length(hs)]:=c;
  53.                            c:=asmgetchar;
  54.                         end;
  55.                       if upper(hs)='END' then ende:=true
  56.                       else
  57.                          begin
  58.                             { access to local varaibles }
  59.                             if assigned(aktprocsym) then
  60.                               begin
  61.                                  if (s[length(s)]<>'%') and
  62.                                    (s[length(s)]<>'$') then
  63.                                    begin
  64.                                       sym:=aktprocsym^.definition^.localst^.search(upper(hs));
  65.                                       if assigned(sym) then
  66.                                         begin
  67.                                            if sym^.typ=varsym then
  68.                                              hs:='-'+tostr(pvarsym(sym)^.adresse)+'(%ebp)';
  69.                                         end
  70.                                       else
  71.                                         begin
  72.                                            sym:=aktprocsym^.definition^.parast^.search(upper(hs));
  73.                                            if assigned(sym) then
  74.                                              begin
  75.                                                 if sym^.typ=varsym then
  76.                                                   begin
  77.                                                      l:=pvarsym(sym)^.adresse;
  78.                                                      { set offset }
  79.                                                      inc(l,longint(aktprocsym^.definition^.parast^.name));
  80.                                                      hs:=tostr(l)+'(%ebp)';
  81.                                                   end;
  82.                                              end
  83.                                            else if upper(hs)='__SELF' then
  84.                                              begin
  85.                                                 if assigned(procinfo._class) then
  86.                                                   hs:=tostr(procinfo.ESI_offset)+'(%ebp)';
  87.                                              end
  88.                                            else if upper(hs)='__RESULT' then
  89.                                              begin
  90.                                                 if assigned(procinfo.retdef) then
  91.                                                   hs:=tostr(procinfo.retoffset)+'(%ebp)';
  92.                                              end
  93.                                            else if upper(hs)='__OLDEBP' then
  94.                                              begin
  95.                                                 { complicate to check there }
  96.                                                 { we do it: }
  97.                                                 hs:=tostr(procinfo.framepointer_offset)+'(%ebp)';
  98.                                              end;
  99.                                         end;
  100.                                    end;
  101.                               end;
  102.                             s:=s+hs;
  103.                          end;
  104.                    end;
  105.                  ';' : begin
  106.                            while c<>#10 do
  107.                              c:=asmgetchar;
  108.                        end;
  109.                  #10 : begin
  110.                           code^.concat(gennasmrec(DIRECT,S_NO,s));
  111.                           s:='';
  112.                           c:=asmgetchar;
  113.                           write_line;
  114.                        end;
  115.                  #13 : c:=asmgetchar;
  116.                  #26 : fatalerror(endoffile);
  117.                  else
  118.                    begin
  119.                       inc(byte(s[0]));
  120.                       s[length(s)]:=c;
  121.                       c:=asmgetchar;
  122.                    end;
  123.               end;
  124.            end;
  125.          code^.insert(gennasmrec(DIRECT,S_NO,s));
  126.          assemble:=genasmnode(code);
  127.       end;
  128.  
  129. end.
  130.